package com.guaju.yueshangLife.adapter;

import android.app.Activity;
import android.content.Context;
import android.support.v7.view.menu.MenuView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.facebook.drawee.view.SimpleDraweeView;
import com.guaju.yueshangLife.R;
import com.guaju.yueshangLife.bean.OrderDetailBean;
import com.guaju.yueshangLife.widget.dilivery.LineItem;

import java.util.List;

public class DeliveryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    Context context;
    List<OrderDetailBean.DataBean.ShipDataBean.DetailBean> list;
    private int status = 1;


    Activity activity;
    private final LayoutInflater layoutInflater;
    private View view;

    public DeliveryAdapter(Context context, List<OrderDetailBean.DataBean.ShipDataBean.DetailBean> list) {
        this.context = context;
        this.list = list;
        activity = (Activity) context;
        layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int type) {
        View view = layoutInflater.inflate(R.layout.item_delivery, parent, false);
        InnerHolder innerHolder = new InnerHolder(view);
        return innerHolder;

    }

    //绑定
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        InnerHolder innerHolder = (InnerHolder) holder;
        if (position==0){
            innerHolder.item.setIsLast(true);
        }else if (position==list.size()-1){
            innerHolder.item.setIsFirst(true);
        }else{
            innerHolder.item.setIsFirst(false);
            innerHolder.item.setIsLast(false);
        }
        innerHolder.setContent(list.get(position));
    }

    //有多少个item？
    @Override
    public int getItemCount() {
        if (list!=null){
        return list.size();
        }else{
            return 0;
        }
    }


    public interface OnItemClickListener {
        void onItemClick(View v, int position);

        void onItemLongClick(View v);
    }

    public DeliveryAdapter.OnItemClickListener mOnItemClickListener;//第二步：声明自定义的接口

    //第三步：定义方法并暴露给外面的调用者
    public void setOnItemClickListener(DeliveryAdapter.OnItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }


    class InnerHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        private final LineItem item;

        public InnerHolder(View itemView) {
            super(itemView);
            item = (LineItem) itemView;

        }

        public void setContent(OrderDetailBean.DataBean.ShipDataBean.DetailBean bean) {
            item.setProgress(bean);
        }

        @Override
        public void onClick(View v) {
        }
    }


}
